<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>月度运维巡检报告</title>
    <script src="https://cdn.jsdelivr.net/npm/echarts@5.4.3/dist/echarts.min.js"></script>
    <style>
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }

        body {
            font-family: 'Arial', sans-serif;
            display: flex;
            min-height: 100vh;
            color: #333;
            line-height: 1.6;
        }

        .sidebar {
            width: 450px;
            background-color: #f8f9fa;
            border-right: 1px solid #e1e4e8;
            padding: 20px 0;
            position: sticky;
            top: 0;
            height: 100vh;
            overflow-y: auto;
        }

        .sidebar-header {
            padding: 0 20px 15px;
            border-bottom: 1px solid #e1e4e8;
            margin-bottom: 15px;
        }

        .sidebar-title {
            font-size: 18px;
            font-weight: bold;
            color: #24292e;
        }

        .nav-menu {
            list-style: none;
            padding-left: 0;
        }

        .nav-item {
            position: relative;
        }

        .nav-link {
            display: flex;
            align-items: center;
            padding: 8px 15px;
            color: #586069;
            text-decoration: none;
            transition: all 0.2s;
            border-left: 3px solid transparent;
        }

        /* 修复折叠按钮样式 - 确保可见 */
        .nav-toggle {
            display: inline-block;
            width: 16px;
            height: 16px;
            margin-right: 8px;
            color: #586069;
            text-align: center;
            cursor: pointer;
            font-size: 12px;
            line-height: 16px;
            visibility: visible;
            opacity: 1;
        }

        .nav-toggle::before {
            content: '▶';
            display: block;
        }

        .nav-item.open > .nav-link > .nav-toggle::before {
            content: '▼';
        }

        /* 无子菜单的项隐藏按钮但保留空间 */
        .nav-item:not(.has-children) > .nav-link > .nav-toggle {
            visibility: hidden;
        }

        .nav-menu .nav-menu {
            padding-left: 15px;
            display: none;
        }

        .nav-item.open > .nav-menu {
            display: block;
        }

        /* 层级缩进 */
        .nav-item.level-1 > .nav-link { padding-left: 15px; }
        .nav-item.level-2 > .nav-link { padding-left: 30px; font-size: 14px; }
        .nav-item.level-3 > .nav-link { padding-left: 45px; font-size: 13px; }
        .nav-item.level-4 > .nav-link { padding-left: 60px; font-size: 12px; }

        .nav-link:hover {
            color: #0366d6;
            background-color: rgba(3, 102, 214, 0.05);
        }

        .nav-link.active {
            color: #0366d6;
            font-weight: 500;
            background-color: rgba(3, 102, 214, 0.1);
            border-left-color: #0366d6;
        }

        .content {
            flex: 1;
            padding: 30px;
            background-color: #fff;
        }

        /* 新增文本内容样式 */
        .content-text {
            font-size: 14px;
            line-height: 1.8;
            color: #444;
            margin-bottom: 20px;
            text-indent: 2em; /* 中文段落首行缩进 */
        }

        .content-list {
            margin: 15px 0;
            padding-left: 1.5em;
            list-style-type: none;
        }

        .content-list li {
            position: relative;
            margin-bottom: 8px;
            padding-left: 1.2em;
        }

        .content-list li::before {
            content: "•";
            color: #0366d6; /* 与导航高亮色保持一致 */
            position: absolute;
            left: 0;
            font-size: 1.1em;
        }


        .chart-section {
            margin-bottom: 50px;
            scroll-margin-top: 20px;
        }

        .section-title {
            margin-bottom: 20px;
            padding-bottom: 10px;
            border-bottom: 1px solid #eaecef;
            color: #24292e;
        }

        .title-level-1 { font-size: 24px; font-weight: 600; margin-top: 30px; border-bottom: 2px solid #eaecef; }
        .title-level-2 { font-size: 20px; font-weight: 500; margin-top: 25px; }
        .title-level-3 { font-size: 18px; font-weight: 500; margin-top: 20px; color: #444; }
        .title-level-4 { font-size: 16px; font-weight: 500; margin-top: 20px; color: #444; }

        .chart-container {
            width: 100%;
            height: 450px;
            border: 1px solid #e1e4e8;
            border-radius: 4px;
            padding: 15px;
            min-width: 400px;
            min-height: 350px;
            background-color: #fff;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
            margin-top: 15px;
        }

        /* 新增表格样式 */
        .content-table {
            width: 100%;
            border-collapse: collapse;
            margin: 20px 0;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05); /* 与图表阴影一致 */
            border-radius: 4px;
            overflow: hidden;
        }

        .content-table th,
        .content-table td {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid #e1e4e8; /* 与侧边栏边框色一致 */
            font-size: 14px; /* 与正文文字大小一致 */
        }

        .content-table th {
            background-color: #f8f9fa; /* 与侧边栏背景色一致 */
            font-weight: 500;
            color: #24292e; /* 主标题颜色 */
            border-bottom: 2px solid #eaecef; /* 与标题下划线一致 */
        }

        .content-table tr:hover {
            background-color: rgba(3, 102, 214, 0.05); /* 与导航悬停效果一致 */
        }

        .content-table tr:nth-child(even) {
            background-color: #fafbfc; /* 交替行背景色 */
        }

        /* 移动端适配 */
        @media (max-width: 992px) {
            body { flex-direction: column; }
            .sidebar {
                width: 100%;
                height: auto;
                /*max-height: 300px;*/
                position: static;
                border-right: none;
                border-bottom: 1px solid #e1e4e8;
            }
            .content { padding: 20px; }
        }
    </style>
</head>
<body>
<!-- 左侧导航 -->
<aside class="sidebar" id="sidebar">
    <div class="sidebar-header">
        <h2 class="sidebar-title">月度运维巡检报告</h2>
    </div>
    <ul class="nav-menu" id="navMenu"></ul>
</aside>

<!-- 右侧内容区 -->
<main class="content" id="content">


    <!-- 一级标题 -->
<!--
    <section id="user-analysis" class="chart-section">
        <h1 class="section-title title-level-1">用户分析</h1>

        &lt;!&ndash; 二级标题 - 折线图 &ndash;&gt;
        <section id="user-growth" class="chart-section">
            <h2 class="section-title title-level-2">用户增长趋势</h2>
            <div class="chart-container"></div>
        </section>

        &lt;!&ndash; 二级标题 - 饼图 &ndash;&gt;
        <section id="user-distribution" class="chart-section">
            <h2 class="section-title title-level-2">用户分布</h2>
            <div class="chart-container"></div>
        </section>
    </section>
-->


    <!-- ##########################  变量  ############################################# -->
    <!-- 一级标题  -->
    ${titleLevel}

</main>

<script>
    // 等待DOM加载完成
    document.addEventListener('DOMContentLoaded', function() {
        // 1. 自动生成导航菜单
        generateNavigation();

        // 2. 初始化所有图表
        initAllCharts();

        // 3. 设置滚动监听和高亮
        setupScrollSpy();

        // 4. 设置平滑滚动
        setupSmoothScrolling();

        // 默认展开一级菜单
        document.querySelectorAll('.nav-item.level-1').forEach(item => {
            item.classList.add('open');
        });
    });




    // 自动生成完整层级导航菜单
    function generateNavigation() {
        const navMenu = document.getElementById('navMenu');
        const sections = document.querySelectorAll('.chart-section');
        const navMap = new Map(); // 用于记录每个层级的最后一个父项

        sections.forEach(section => {
            const title = section.querySelector('.section-title');
            const level = getTitleLevel(title);
            const id = section.id;
            const text = title.textContent;

            const li = document.createElement('li');
            li.className = 'nav-item level-'+level+' has-children';

            const link = document.createElement('a');
            link.href = '#'+id;
            link.className = 'nav-link';


            const toggle = document.createElement('span');
            toggle.className = 'nav-toggle';
            link.prepend(toggle);

            link.appendChild(document.createTextNode(text));
            li.appendChild(link);


            const childMenu = document.createElement('ul');
            childMenu.className = 'nav-menu';
            li.appendChild(childMenu);

            let parentNav = null;

            navMap.set(level, li);


            if (level > 1) {

                for (let i = level - 1; i >= 1; i--) {
                    if (navMap.has(i)) {
                        parentNav = navMap.get(i);

                        break;
                    }
                }
            }

            // console.log(navMap)

            if (parentNav) {
                parentNav.querySelector('ul').appendChild(li);
            } else {
                navMenu.appendChild(li);
            }
        });

        // 移除没有子项的导航项的折叠按钮
        document.querySelectorAll('.nav-item').forEach(item => {
            if (!item.querySelector('ul').children.length) {
                item.classList.remove('has-children');
                item.querySelector('.nav-toggle').remove();
            }
        });

        // 添加折叠功能
        document.querySelectorAll('.nav-toggle').forEach(toggle => {
            toggle.addEventListener('click', function (e) {
                e.stopPropagation();
                this.closest('.nav-item').classList.toggle('open');
            });
        });
    }
    // 获取标题层级
    function getTitleLevel(titleElement) {
        if (titleElement.classList.contains('title-level-1')) return 1;
        if (titleElement.classList.contains('title-level-2')) return 2;
        if (titleElement.classList.contains('title-level-3')) return 3;
        if (titleElement.classList.contains('title-level-4')) return 4;
        return 1; // 默认一级
    }

    // 图表配置数据
    const chartConfigs = {
        // // 销售分析
        // 'monthly-sales': {
        //     type: 'line',
        //     title: '月度销售趋势',
        //     data: {
        //         xAxis: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
        //         series: [
        //             {
        //                 name: '销售额',
        //                 data: [120, 132, 101, 134, 90, 230, 210, 182, 191, 234, 290, 330],
        //                 color: '#5470C6'
        //             }
        //         ]
        //     }
        // },
        // 'product-sales': {
        //     type: 'bar',
        //     title: '产品销售额',
        //     data: {
        //         xAxis: ['产品A', '产品B', '产品C', '产品D', '产品E'],
        //         series: [
        //             {
        //                 name: '销售额',
        //                 data: [450, 520, 380, 290, 620],
        //                 color: '#91CC75'
        //             }
        //         ]
        //     }
        // },


        // 'user-distribution': {
        //     type: 'pie',
        //     title: '用户分布',
        //     data: {
        //         series: [
        //             {
        //                 name: '用户分布',
        //                 data: [
        //                     { value: 335, name: '华东', itemStyle: { color: '#5470C6' } },
        //                     { value: 310, name: '华北', itemStyle: { color: '#91CC75' } },
        //                     { value: 234, name: '华南', itemStyle: { color: '#FAC858' } },
        //                     { value: 135, name: '西部', itemStyle: { color: '#EE6666' } },
        //                     { value: 154, name: '其他', itemStyle: { color: '#73C0DE' } }
        //                 ]
        //             }
        //         ]
        //     }
        // },

        <!-- ##########################  变量  ############################################# -->
        // 图标数据内容
        ${chartContent}
    };

    // 初始化所有图表
    function initAllCharts() {
        document.querySelectorAll('.chart-container').forEach(container => {
            const sectionId = container.parentElement.id;
            const config = chartConfigs[sectionId];
            const chart = echarts.init(container);

            if (!config) {
                console.warn(`No config found for section: `+ sectionId);
                return;
            }

            // 根据类型生成不同的配置
            let option;
            switch(config.type) {
                case 'line':
                    option = getLineOption(config);
                    break;
                case 'bar':
                    option = getBarOption(config);
                    break;
                case 'pie':
                    option = getPieOption(config);
                    break;
                default:
                    option = getLineOption(config);
            }

            chart.setOption(option);

            // 响应式调整
            new ResizeObserver(() => chart.resize()).observe(container);
        });
    }

    // 获取折线图配置
    function getLineOption(config) {
        return {
            title: {
                text: config.title,
                left: 'center'
            },
            tooltip: {
                trigger: 'axis',
                formatter: '{b}<br/>{a}: {c}'
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: {
                type: 'category',
                boundaryGap: false,
                data: config.data.xAxis
            },
            yAxis: {
                type: 'value'
            },
            series: config.data.series.map(series => ({
                name: series.name,
                type: 'line',
                data: series.data,
                smooth: true,
                label: {
                    show: true,
                    position: 'top'
                },
                lineStyle: {
                    width: 3,
                    color: series.color
                },
                itemStyle: {
                    color: series.color
                },
                areaStyle: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                        { offset: 0, color: hexToRgba(series.color, 0.5) },
                        { offset: 1, color: hexToRgba(series.color, 0.1) }
                    ])
                }
            }))
        };
    }

    // 获取柱形图配置
    function getBarOption(config) {
        return {
            title: {
                text: config.title,
                left: 'center'
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'shadow'
                },
                formatter: '{b}<br/>{a}: {c}'
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: {
                type: 'category',
                data: config.data.xAxis
            },
            yAxis: {
                type: 'value'
            },
            series: config.data.series.map(series => ({
                name: series.name,
                type: 'bar',
                data: series.data,
                label: {
                    show: true,
                    position: 'top'
                },
                itemStyle: {
                    color: series.color
                },
                emphasis: {
                    itemStyle: {
                        color: hexToRgba(series.color, 0.7)
                    }
                }
            }))
        };
    }

    // 获取饼图配置
    function getPieOption(config) {
        return {
            title: {
                text: config.title,
                left: 'center'
            },
            tooltip: {
                trigger: 'item',
                formatter: '{a} <br/>{b}: {c} ({d}%)'
            },
            legend: {
                orient: 'vertical',
                left: 'left',
                data: config.data.series[0].data.map(item => item.name)
            },
            series: config.data.series.map(series => ({
                name: series.name,
                type: 'pie',
                radius: series.radius || '50%',
                data: series.data,
                label: {
                    formatter: '{b}: {c} ({d}%)'
                },
                emphasis: {
                    itemStyle: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }))
        };
    }

    // 十六进制颜色转RGBA
    function hexToRgba(hex, alpha) {
        const r = parseInt(hex.slice(1, 3), 16);
        const g = parseInt(hex.slice(3, 5), 16);
        const b = parseInt(hex.slice(5, 7), 16);

        return  "rgba(" + r + ", " + g + ", " + b + ", " + alpha + ")";
    }

    // 设置滚动监听和高亮
    function setupScrollSpy() {
        const sections = document.querySelectorAll('.chart-section');
        const navLinks = document.querySelectorAll('.nav-link');

        const observer = new IntersectionObserver((entries) => {
            entries.forEach(entry => {
                if (entry.isIntersecting) {
                    const id = entry.target.id;
                    navLinks.forEach(link => {

                        link.classList.toggle('active', link.getAttribute('href') === "#" + id);
                    });
                }
            });
        }, {
            threshold: 0.5,
            rootMargin: '0px 0px -50% 0px'
        });

        sections.forEach(section => observer.observe(section));
    }

    // 设置平滑滚动
    function setupSmoothScrolling() {
        document.querySelectorAll('.nav-link').forEach(link => {
            link.addEventListener('click', function(e) {
                e.preventDefault();
                const targetId = this.getAttribute('href');
                const targetSection = document.querySelector(targetId);

                if (targetSection) {
                    targetSection.scrollIntoView({
                        behavior: 'smooth',
                        block: 'start'
                    });

                    // 更新URL哈希
                    history.pushState(null, null, targetId);
                }
            });
        });
    }
</script>
</body>
</html>